<html>
<body>
<head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <link rel="stylesheet" href="${base}/layui/css/layui.css">
        <link href="${base}/laypage/skin/laypage.css" rel="stylesheet" type="text/css" />
 </head>
 <#assign base=request.contextPath />
 
	<div style="float:right">
		<h3 >欢迎  ${admin.name} 管理员登录</h3 > 
		<img  src="${base}/upload/${admin.head}" height="60px" width="60px" />
	</div>

<h2>员工信息</h2>
<table border="1px" id="table">
<tr>
	<td>员工编号</td> <td>员工名称</td><td>员工职位</td><td>员工工资</td><td>员工上司编号</td><td>操作</td>
</tr>
<#list page.pageList as emp>
<tr id="${emp.empNo}">
	<td>${emp.empNo}</td>
	<td>${emp.empName}</td>
	<td>${emp.job}</td>
	<td>${emp.mgr}</td>
	<td>${emp.salary}</td>
	<td><a href="/emp/add1">增加&nbsp;&nbsp;</a>
		<a href="javascript:void(0)" onclick="del(${emp.empNo},${page.pageIndex})">删除&nbsp;&nbsp;</a>
		<a href="/emp/update1.action?empno=${emp.empNo}">修改&nbsp;&nbsp;</a>
		</td>
</tr>
</#list>
 <tr>
 	<td colspan="6">
 		${page.pageIndex}/${page.pageTotal}
 		<a id="before" href="javascript:void(0)" onclick="Page(${page.pageIndex-1})">上一页</a>
		<a id="after" href="javascript:void(0)" onclick="Page(${page.pageIndex+1})" >下一页</a>
 	</td>
 </tr>
</table>
	<div id="page" class="page"></div>
<script  type="text/javascript" charset="utf-8" src="${base}/jquery-1.8.0.min.js"></script>
<script src="${base}/layui/layui.js"></script>
<script src="${base}/laypage/laypage.js"></script>
<script type="text/javascript">
//删除
function del(num,index){
	$.ajax({
			type:"post",
			data:"empno="+num+"&index="+index,
			url:"/emp/del",
			dataType:"json",
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			success:function(data){
				$("#table tr:not(:eq(0))").remove();
				var pages;
				var curr=1;
				for(var i in data.pageList){
					var tr="<tr> <td>";
					tr+=data.pageList[i].empNo+" </td> <td>";
					tr+=data.pageList[i].empName+" </td> <td>";
					tr+=data.pageList[i].job+" </td> <td>";
					tr+=data.pageList[i].mgr+" </td> <td>";
					tr+=data.pageList[i].salary+" </td> <td>";
					tr+="<a href='/emp/add1' >增加&nbsp;&nbsp;</a>";
					tr+="<a href='javascript:void(0)' onclick='del("+data.pageList[i].empNo+","+data.pageIndex+")'>删除&nbsp;&nbsp;</a>";
					tr+="<a href='/emp/update1.action?empno="+data.pageList[i].empNo+"'>修改&nbsp;&nbsp;</a></td>";
					tr+="";
					tr+="</td> </tr>";
					$("table").append(tr);
					tr="";
				}
				pages=data.pageTotal;
				curr=data.pageIndex; //设置当前的页数
				 laypage({
                        cont: 'page',
                        pages: pages,
                        curr: curr || 1, //当前页
                        jump: function (obj,first) {
                           if(!first){
              					//   alert('当前页'+obj.curr);
              					Page(obj.curr);
              				}
                        }
                    })
				var ntr="<tr><td colspan='6'>"+data.pageIndex+"/"+data.pageTotal;
				    ntr+="<a  href='javascript:void(0)' onclick='Page("+(data.pageIndex-1)+")'>上一页</a>";
				    ntr+="<a  href='javascript:void(0)' onclick='Page("+(data.pageIndex+1)+")' >下一页</a></td></tr>";
				$("table").append(ntr);
				
			}
		});
};
//翻页异步ajax
function Page(data){
	//alert(data);
	$.ajax({
			type:"post",
			data:"index="+data,
			url:"/emp/page",
			dataType:"json",
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			success:function(data){
				$("#table tr:not(:eq(0))").remove();
				var pages;
				var curr=1;
				for(var i in data.pageList){
					var tr="<tr> <td>";
					tr+=data.pageList[i].empNo+" </td> <td>";
					tr+=data.pageList[i].empName+" </td> <td>";
					tr+=data.pageList[i].job+" </td> <td>";
					tr+=data.pageList[i].mgr+" </td> <td>";
					tr+=data.pageList[i].salary+" </td> <td>";
					tr+="<a href='/emp/add1' >增加&nbsp;&nbsp;</a>";
					tr+="<a href='javascript:void(0)' onclick='del("+data.pageList[i].empNo+","+data.pageIndex+")'>删除&nbsp;&nbsp;</a>";
					tr+="<a href='/emp/update1.action?empno="+data.pageList[i].empNo+"'>修改&nbsp;&nbsp;</a></td>";
					tr+="";
					tr+="</td> </tr>";
					$("table").append(tr);
					tr="";
				}
				pages=data.pageTotal;
				curr=data.pageIndex; //设置当前的页数
				 laypage({
                        cont: 'page',
                        pages: pages,
                        curr: curr || 1, //当前页
                        jump: function (obj,first) {
                           if(!first){
              					//   alert('当前页'+obj.curr);
              					Page(obj.curr);
              				}
                        }
                    })
				var ntr="<tr><td colspan='6'>"+data.pageIndex+"/"+data.pageTotal;
				    ntr+="<a  href='javascript:void(0)' onclick='Page("+(data.pageIndex-1)+")'>上一页</a>";
				    ntr+="<a  href='javascript:void(0)' onclick='Page("+(data.pageIndex+1)+")' >下一页</a></td></tr>";
				$("table").append(ntr);
			}
		});
};
$(function (){

	$.ajax({
			type:"post",
			url:"/emp/pages",
			dataType:"text",
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			success:function(data){
				var pages=data;
				laypage({
              	cont: 'page',
              	pages: pages,
              	jump: function (obj,first) {
              			if(!first){
              				Page(obj.curr);
              			}
               		
        			}
 					});
			}
		});
});
</script>
</body>
</html>